<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        #box{
            width: 200px;
            height: 50px;
            padding: 20px;
            border: 3px solid #f00;
            font-size: 50px;
            color:#f00;
            text-align: center;
            line-height: 50px;
        }
    </style>
</head>
<body>
    <h1>JS 单次定时倒计时</h1>
    <button onclick="strat()">开始</button>
    <hr>

    <div id="box">10</div>

    <script>

        var m = 10;
        function strat() {
            var div = document.getElementById('box');
            // console.log(div);
            
            m--;
            div.innerHTML = m;

            if (m <= 0) {
                // clearTimeout(timer);
                return;
            }
            timer = setTimeout('strat()', 200);
        }
    </script>
</body>
</html>